package com.zhai.boot.dao.table;

import com.zhai.boot.common.LogConstant;
import com.zhai.boot.domain.table.DemoTable;
import com.zhai.boot.mapper.DemoMapper;
import com.zhai.boot.util.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @package: com.zhai.boot.dao
 * @project-name: zhai-boot
 * @description: demo Dao 实现
 * @author: Created by 翟凤玺
 * @create-datetime: 2018-8-2 10:36
 */
@Slf4j
@Service
public class DemoDaoImpl implements DemoDao {

    private static final String BUSINESS_NAME = "【demo数据层】";

    @Autowired
    private DemoMapper demoMapper;


    @Override
    public DemoTable getById(String id) {
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据ID查询。" + LogConstant.IN + id);
        DemoTable demoTable = demoMapper.getById(id);
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据ID查询。" + LogConstant.OUT + JSONUtil.toStr(demoTable));
        return demoTable;
    }

    @Override
    public DemoTable getByCode(String code) {
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据编号查询。" + LogConstant.IN + code);
        DemoTable demoTable = demoMapper.getByCode(code);
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据编号查询。" + LogConstant.OUT + JSONUtil.toStr(demoTable));
        return demoTable;
    }

    @Override
    public DemoTable getByMain(DemoTable table) {
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据实体查询。" + LogConstant.IN + JSONUtil.toStr(table));
        DemoTable demoTable = demoMapper.getByMain(table);
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据实体查询。" + LogConstant.OUT + JSONUtil.toStr(demoTable));
        return demoTable;
    }

    @Override
    public List<DemoTable> getListByMain(DemoTable table) {
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据实体查询列表。" + LogConstant.IN + JSONUtil.toStr(table));
        List<DemoTable> lists = demoMapper.getListByMain(table);
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "根据实体查询列表。" + LogConstant.OUT + JSONUtil.toStr(lists));
        return lists;
    }

    @Override
    public Integer insert(DemoTable table) {
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "新增。" + LogConstant.IN + JSONUtil.toStr(table));
        Integer insert = demoMapper.insert(table);
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "新增。" + LogConstant.OUT + insert);
        return insert;
    }

    @Override
    public Integer update(DemoTable table) {
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "修改。" + LogConstant.IN + JSONUtil.toStr(table));
        Integer update = demoMapper.update(table);
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "修改。" + LogConstant.OUT + update);
        return update;
    }

    @Override
    public Integer delete(DemoTable table) {
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "删除。" + LogConstant.IN + JSONUtil.toStr(table));
        Integer delete = demoMapper.delete(table);
        log.debug(BUSINESS_NAME + LogConstant.SERVICE + "删除。" + LogConstant.OUT + delete);
        return delete;
    }
}
